<template>
	<view class="body">
		<u-navbar title="实名认证" :autoBack="true" :placeholder="true"></u-navbar>
		<view class="from">
			<view class="name">
				<view><b>姓名</b><span>*</span></view>
				<view>
					<input type="text" v-model="name" placeholder="请输入姓名">
				</view>
			</view>
			<view class="idNumber">
				<view><b>身份证号</b><span>*</span></view>
				<view>
					<input type="number" v-model="idNumber" placeholder="请输入身份证号">
				</view>
			</view>
			<view class="sex">
				<view><b>性别</b><span>*</span></view>
				<u-radio-group placement="row" style="border-bottom: none;margin-top: 10px;padding-bottom: 3vw;"
					v-model="sex">
					<u-radio :key="0" label="男" name="0" style="margin-right: 30px;"></u-radio>
					<u-radio :key="1" label="女" name="1"></u-radio>
				</u-radio-group>
			</view>
			<view style="font-size: 3.5vw;margin-top: 10px;padding: 0;">
				<u-checkbox-group v-model="agreement">
					<u-checkbox size="15" :name="true" />我承诺以上信息全部属实，否则将承担相关法律责任！
				</u-checkbox-group>
			</view>
			<u-button type="primary" text="确定" style="margin-top: 5vw;" @click="submit"></u-button>
		</view>
	</view>
</template>
<script>
	import {
		rear
	} from '@/config/api.js';

	export default {
		data() {
			return {
				name: "",
				idNumber: "",
				sex: "0",
				agreement: [],
				user: null
			}
		},
		methods: {
			submit() {
				if (this.name == "") {
					uni.showToast({
						title: '姓名不能为空',
						icon: 'none',
						duration: 1000,
					});
					return;
				}
				if (this.idNumber == "") {
					uni.showToast({
						title: '身份证号不能为空',
						icon: 'none',
						duration: 1000,
					});
					return;
				}
				if (this.agreement.length == 0) {
					uni.showToast({
						title: '请勾选确认用户协议',
						icon: 'none',
						duration: 1000, 
					});
					return;
				}
				uni.request({
					url: rear + "/standing/addStanding",
					method: "POST",
					data: {
						name: this.name,
						idNumber: this.idNumber,
						sex: this.sex,
						userId: this.user.id
					},
					success: (res) => {
						if (res.data.code == 200) {
							this.user.standing = res.data.data;
							uni.setStorageSync('user', this.user);
							uni.showToast({
								title: '认证成功 ！',
								icon: 'none',
								duration: 1000,
							});
							uni.navigateBack({
								delta: 1
							});
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 1000,
							});
						}
					}
				});
			}
		},
		onShow() {
			this.user = uni.getStorageSync('user');
		}
	}
</script>
<style lang="scss">
	.body {
		height: 100vh;

		.from {
			margin-top: 10vh;
			padding: 5vw;

			>view {
				margin-top: 8px;

				>view:nth-of-type(1) {
					>span {
						color: red;
					}
				}

				>view:nth-of-type(2) {
					margin: 6px 0 3px 0;
					border-bottom: 0.05vh solid black;

					input {
						height: 6vw;
					}
				}
			}
		}
	}
</style>